﻿using UnityEngine;
using System.Collections;
using System;

public class Enemy : MonoBehaviour {

    //移动速度
    public float m_speed = 1;
    //生命属性
    public float m_life = 10;
    //旋转速度
    protected float m_rotSpeed = 30;

    protected Transform m_transform;

	// Use this for initialization
	void Start () {
        m_transform = this.transform;
	}
	
	// Update is called once per frame
	void Update () {
        UpdateMove();
	}

    void OnTriggerEnter(Collider other)
    {
        switch(other.tag)
        {
            case "PlayerRocket":
                Rocket rocket = other.GetComponent<Rocket>();
                if (rocket != null)
                {
                    m_life -= rocket.m_power;

                    if (m_life <= 0)
                    {
                        Destroy(this.gameObject);
                    }
                }
                break;
            case "Player":
            case "bound":
                m_life = 0;
                Destroy(this.gameObject);
                break;
            default:
                break;
        }
    }

    protected virtual void UpdateMove()
    {
        //左右移动
        float rx = Mathf.Sin(Time.time) * Time.deltaTime;
        //前进
        m_transform.Translate(new Vector3(rx, 0, -m_speed * Time.deltaTime));
    }
}
